/*
 * PayWayHolder.java
 * business
 *
 * Created by ChenTao on 2017/2/22.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.viewholder;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.data.bean.PayWay;
import com.yidiandao.business.ui.widget.listview.ViewHolder;
import com.yidiandao.business.utils.ImageLoader;
import com.yidiandao.business.utils.UIUtils;

/**
 * 支付方式
 * <p>
 * <p>Created by ChenTao(chentao7v@gmail.com) on 2017/2/22 9:55
 */
public class PayWayHolder extends ViewHolder {

    private ImageView ivPayWay;

    private TextView tvPayWay;

    private ImageView ivSelected;

    private TextView tvRate;

    @Override
    protected void initView(View rootView) {
        ivPayWay = (ImageView) rootView.findViewById(R.id.iv_pay_way);
        tvPayWay = (TextView) rootView.findViewById(R.id.tv_pay_way);
        ivSelected = (ImageView) rootView.findViewById(R.id.iv_selected);
        tvRate = (TextView) rootView.findViewById(R.id.tv_rate);
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_pay_way;
    }

    public void refreshUI(PayWay payWay) {
        ImageLoader.loadImage(mContext, ivPayWay, payWay.getPayIcon());
        tvPayWay.setText(payWay.getName());
        ivSelected.setVisibility(payWay.isSelected() ? View.VISIBLE : View.GONE);

        tvPayWay.setTextColor(UIUtils.getColor(payWay.isCanChoose() ? R.color.text_color_3 : R.color.text_color_8));

        float payFee = payWay.getPayFee();
        if (payFee != 0) {
            String result = payFee * 100 + "%";
            tvRate.setVisibility(View.VISIBLE);
            tvRate.setText(UIUtils.getString(R.string.pay_way_rate, result));
        } else {
            tvRate.setVisibility(View.GONE);
        }
    }
}
